import 'package:basic_ui/constants/app_sizes.dart';
import 'package:flutter/material.dart';

/// 统一的小部件集合，包含常用的部件，如占位符、按钮、图标等。
class MySmallWidgets {
  // 返回一个占位符 widget，作为临时显示内容
  static Widget placeholderWidget() {
    return const Placeholder();
  }

  // 返回一个带有箭头图标的 ListTile "trailing" 部件，统一图标大小
  static Widget listTileTrailingIcon({
    double size = Sizes.p14, // 可以传递大小值，默认为 20
    Color color = Colors.black, // 可以传递颜色，默认为黑色
  }) {
    return Icon(
      Icons.arrow_forward_ios,
      size: size,
      color: color,
    );
  }

  // 通用按钮，常用的 ElevatedButton 封装
  static Widget elevatedButton({
    required String label,
    required VoidCallback onPressed,
    Color backgroundColor = Colors.blue,
    Color textColor = Colors.white,
    double paddingVertical = 12.0,
    double paddingHorizontal = 20.0,
  }) {
    return ElevatedButton(
      onPressed: onPressed,
      style: ElevatedButton.styleFrom(
        backgroundColor: backgroundColor,
        padding: EdgeInsets.symmetric(
            vertical: paddingVertical, horizontal: paddingHorizontal),
      ),
      child: Text(
        label,
        style: TextStyle(color: textColor),
      ),
    );
  }

  // 通用输入框小部件，封装 TextField
  static Widget customTextField({
    required TextEditingController controller,
    required String labelText,
    TextInputType keyboardType = TextInputType.text,
    String? Function(String?)? validator,
    bool obscureText = false,
    IconData? prefixIcon,
  }) {
    return TextField(
      controller: controller,
      keyboardType: keyboardType,
      obscureText: obscureText,
      decoration: InputDecoration(
        labelText: labelText,
        prefixIcon: prefixIcon != null ? Icon(prefixIcon) : null,
        border: const OutlineInputBorder(),
        contentPadding:
            const EdgeInsets.symmetric(vertical: 16.0, horizontal: 16.0),
      ),
    );
  }

  // 通用的带图标的按钮
  static Widget iconButton({
    required IconData icon,
    required VoidCallback onPressed,
    double iconSize = 24.0,
    Color iconColor = Colors.black,
  }) {
    return IconButton(
      onPressed: onPressed,
      icon: Icon(
        icon,
        size: iconSize,
        color: iconColor,
      ),
    );
  }

  // 通用的文本显示
  static Widget textWidget({
    required String text,
    TextStyle? style,
    TextAlign textAlign = TextAlign.left,
  }) {
    return Text(
      text,
      style: style ?? const TextStyle(fontSize: 16),
      textAlign: textAlign,
    );
  }

  // 通用的分隔线（比如列表之间的分隔）
  static Widget divider() {
    return const Divider(
      color: Colors.grey,
      thickness: 1,
      height: 1,
    );
  }

  // 统一处理的Card小部件，可以传入内容并控制间距、颜色
  static Widget customCard({
    required Widget child,
    Color backgroundColor = Colors.white,
    EdgeInsetsGeometry margin = const EdgeInsets.all(8.0),
    EdgeInsetsGeometry padding = const EdgeInsets.all(16.0),
  }) {
    return Card(
      color: backgroundColor,
      margin: margin,
      child: Padding(
        padding: padding,
        child: child,
      ),
    );
  }
}
